﻿using System;
using System.Collections.Generic;
using Codeflows.Tracking;

namespace CodeflowsTests.Mocks
{
    public class InMemoryTracker : ICodeflowTracker
    {
        readonly Dictionary<Guid, CodeflowInstance> _store = new Dictionary<Guid, CodeflowInstance>();

        public Guid Create(CodeflowInstance codeflowInstance)
        {
            codeflowInstance.CodeflowId = Guid.NewGuid();
            _store[codeflowInstance.CodeflowId] = codeflowInstance;
            return codeflowInstance.CodeflowId;
        }

        public CodeflowInstance Read(Guid codeflowId)
        {
            return _store[codeflowId];
        }

        public IList<CodeflowInstance> ReadNext(int count)
        {
            throw new NotImplementedException();
        }

        public IList<CodeflowInstance> ReadReadyList(int count)
        {
            throw new NotImplementedException();
        }

        public void Update(IEnumerable<CodeflowInstance> codeflowInstances)
        {
            foreach (var codeflowInstance in codeflowInstances)
            {
                Update(codeflowInstance);
            }
        }

        public void Update(CodeflowInstance codeflowInstance)
        {
            _store[codeflowInstance.CodeflowId] = codeflowInstance;
        }

        public void Dispose()
        {            
        }
    }
}
